//html的要求登录才能进入的
function judgeLogin() {
    $.ajax({
        url:"http://localhost:8080/shop_api/JS",
        type:"get",
        success:function (data) {
            var code = JSON.parse(data).code;
            var msg = JSON.parse(data).msg;
            var user = JSON.parse(data).data;
            console.log("0000000000000")
            console.log(user);
            if (code===100){
                //未登录状态
                alert(msg);
                window.location.href="http://localhost:8080/views/shop/login.html";
                return;
            }
            //登录状态
            return user;
        }
    });
}


function OnDisplay() {
    $.ajax({
        url:"http://localhost:8080/shop_api/JS",
        type:"get",
        success:function (data) {
            var BaseRespVO = JSON.parse(data);
            var code = BaseRespVO.code;
            var user = BaseRespVO.data;
            console.log(code);
            if (code==100) {
                $("#a1").remove();
                $("#a2").remove();
                $("#AA").append("<a href=\"../../../views/shop/login.html\" id=\"a1\" target=\"_top\" class=\"h\">亲，请登录</a>")
                $("#AA").append("<a href=\"../../../views/shop/register.html\" id=\"a2\" target=\"_top\">&nbsp免费注册</a>")
                return;
            }
            var name;
            if (user.userName!=null){
                name=user.userName;
            } else{
                name=user.email;
            }

            $("#a1").remove();
            $("#a2").remove();

            $("#AA").append("<a href=\"information.html\" id=\"a1\" target=\"_top\" class=\"h\">"+name+"</a>")
            $("#AA").append("<a href=\"../home2.html\" id=\"a2\" onclick=\"out()\" target=\"_top\">&nbsp退出登录</a>")
        }
    })
}


function out() {
    $.ajax({
        url:"http://localhost:8080/shop_api/remove",
        type:"get",
        success:function (data) {
            var parseObj = JSON.parse(data);
            var msg = parseObj.data.msg;
            localStorage.removeItem("client");
            sessionStorage.removeItem("client");
            alert(msg);
            location.reload()
        }
    })
}


function sendEmailCode() {
    $.ajax({
        url:"http://localhost:8080/shop_api/sendEmail",
        type:"get",
        data:{"email":$("#email").val()},
        success:function (data) {
            alert("发送成功")
        }
    })
}

//正则表达式 判断邮箱格式
function checkEmail() {
    var inemail = $("#email").val();
    console.log(inemail);
    var pattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if (!pattern.test(inemail)) {
        alert("邮箱格式错误！");
        return;
    }
}